

// wxwidgets includes
#include "wx/wxprec.h"
#include "wx/thread.h"

#ifndef  WX_PRECOMP
  #include "wx/wx.h"
#endif //precompiled headers

// opencv includes
#include "cv.h"
#include "highgui.h"
 
#include "gui/MainFrame.h"


// main header include
#include "CamThread.h"
#include "gui/wxCamViewWindow.h"
////////////////////////////////////////////////////////////////////
// Method:	Constructor
// Class:	CwxopencvWorker
// Purpose:	Initialize my worker thread
// Input:	pointer to reference frame
// Output:	nothing
////////////////////////////////////////////////////////////////////
CamThread::CamThread( MainFrame *frame ): wxThread( wxTHREAD_DETACHED )
{
	// get frame refrence
	this->frame = frame;

	// start life
	alive = 1;

	//m_pMutex = new wxMutex( );

	return;
}

////////////////////////////////////////////////////////////////////
// Method:	Destructor
// Class:	CwxopencvWorker
// Purpose:	object destructor
// Input:	nothing
// Output:	nothing	
////////////////////////////////////////////////////////////////////
CamThread::~CamThread( )
{
	//m_pMutex=NULL;
	//camView=NULL;
	//frame = NULL;
}

////////////////////////////////////////////////////////////////////
// Method:	On Exit
// Class:	CwxopencvWorker
// Purpose:	do soemthing on exit
// Input:	nothing
// Output:	nothing
////////////////////////////////////////////////////////////////////
void CamThread::OnExit( )
{
	// destroy - clean my place
	//delete( m_pMutex );
}



////////////////////////////////////////////////////////////////////
// Method:		Entry
// Class:		CwxopencvWorker
// Purpose:		the main executable body of my thread
// Input:		nothing
// Output:		void pointer
////////////////////////////////////////////////////////////////////
void *CamThread::Entry( )
{

	////////////////////////////////////////////////////////////////
	// Start Life Cycle
	////////////////////////////////////////////////////////////////
	// loop as long as flag m_bLife = 1
	while( alive )
	{
		
		if( TestDestroy( ) == 1 ) 
			break;
		
		
		
		
		wxMutexGuiEnter();
		
		if(frame->isCamOn() && !frame->isPaused()){
			
			camView->getCamImage();
			
			
		}
		wxMutexGuiLeave();
		
		wxThread::Sleep(10);

	}

	//m_pCamera->Stop( );

    return NULL;
}
